<%--
  Created by IntelliJ IDEA.
  User: 19416
  Date: 2022-08-17
  Time: 9:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="JS/jquery-2.1.1.min.js">

    </script>
</head>
<body>
<form action="${pageContext.request.contextPath}/AddServlet" method="get">
    <h1 >海淀区工商局组织机构管理系统</h1>
<table border="1px">
    <tr>
        <td>组织机构名称(*)</td><td><input type="text" name="name" id="name"><br><span id="span"></span></td>
    </tr>
    <tr>
        <td>负责人(*)</td><td><input type="text" name="principalName" id="principalName"></td>
    </tr>
    <tr>
        <td>创建日期(*)</td><td><input type="text" name="createDate" id="createDate"></td>
    </tr>
    <tr>
        <td><input type="submit" value="提交"> <input type="button" value="返回"></td>
    </tr>
</table>
</form>
<script>
    $("form").submit(function (){
        var name = $("#name").val();
        var principalName = $("#principalName").val();
        var createDate = $("#createDate").val();
        var dateF =/^\d{4}-\d{2}-\d{2}$/
        if (name == "" || principalName == "" || createDate == ""){
            alert("请填写完整的组织机构信息！")
            return false;
        }else if (dateF.test(createDate)){
            alert("日期格式不正确！");
            return false;
        }

    })

    $("#name").blur(function (){
        var name = $("#name").val();
        $.get("NameServlet","name="+name,function (data){
            if (data == "true"){
                $("#span").html("该组织机构已经存在");
                return false;
            }
        })
    })
</script>
</body>
</html>
